package com.example.dockerdemo.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @PACKAGE_NAME: com.example.dockerdemo.aop
 * @NAME: Aopdemo
 * @description:
 * @DATE: 2024/5/10
 * @USER: fz
 **/
@Component
@Aspect
public class AopDemo {

    @Pointcut("execution(* com.example.dockerdemo.aoptarget.Singer.singName(..))")
    public void pointCut() {
    }

    ;

    @Before("pointCut()")
    public void before(JoinPoint joinPoint) {
        System.out.println("before======");
        System.out.println("joinPoint.getThis()===" + joinPoint.getThis());
        System.out.println("joinPoint.getTarget() = " + joinPoint.getTarget());
        System.out.println("joinPoint.getArgs() = " + joinPoint.getArgs());
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            System.out.println("arg = " + arg);
            arg = "fz";
        }
        System.out.println("before======");
    }

    @After("pointCut()")
    public void after(JoinPoint joinPoint) {
        System.out.println("after======");
        System.out.println("joinPoint.getThis()===" + joinPoint.getThis());
        System.out.println("joinPoint.getTarget() = " + joinPoint.getTarget());
        System.out.println("joinPoint.getArgs() = " + joinPoint.getArgs());
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            System.out.println("arg = " + arg);
        }
        System.out.println("after======");
    }

    @Around("pointCut()")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        // 方法执行前逻辑
        System.out.println("First around advice start");
        Object retVal = joinPoint.proceed();
        System.out.println("First around advice end");
        // 方法执行后逻辑
    }

}
